package org.eCon.maven.mojo;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;

import java.io.File;
import java.io.StringWriter;
import java.io.PrintWriter;

/**
 * User: erkink
 * Date: 14-Aug-2008
 * Time: 19:14:08
 */
public abstract class AbstractGWTMojo extends AbstractMojo {
    /**
     * gwt compiler Operating System version
     *
     * @parameter expression="${gwtCompile.gwt_os}"  default-value="${os.name}"
     */
    protected String gwt_os;


    /**
     * Current Directory
     *
     * @parameter expression="${project.basedir}"
     */
    protected File currentDirAsFile;

    /**
     * GWT installation directory
     *
     * @parameter expression="${env.GWT_HOME}"
     * @required
     */
    protected String gwt_Home;

    /**
     * Java installation directory
     *
     * @parameter expression="${env.JAVA_HOME}"
     */
    protected String java_Home;

    /**
     * it will create a bat/sh file to test your gwt
     * in the Google test platform.
     *
     * @parameter
     */
    protected String[] additional_classpathes;
    /**
     * gwt Compiler's module
     *
     * @parameter expression="${gwtCompile.gwt_module}"
     * @required
     */
    protected String gwt_module;

    /**
     * gwt compiler output setting.(Relative to current directory of POM)
     *
     * @parameter
     * @required
     */
    protected String gwt_relative_out;


    /**
     * gwt source directory.(Relative to current directory of POM)
     *
     * @parameter default-value="./src/main/java"
     */
    protected String gwt_relative_src;

    /**
     * jvm parameters to be added
     * @parameter default-value=" -Xms256m "
     */
    protected String jvm_param;

    protected String stack2string(Exception e) {
        try {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            return "------\r\n" + sw.toString() + "------\r\n";
        }
        catch (Exception e2) {
            return "Problem stack2string";
        }
    }


    protected void checkPathes() throws MojoExecutionException {
        if (this.gwt_Home == null) {
            String msg = "GWT_HOME environment variable has to be set.";
            getLog().warn(msg);
            throw new MojoExecutionException(msg);
        }
    }


}
